package com.dx.demo.web;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.dx.demo.bean.Dept;
import com.dx.demo.service.DeptServiceImpl;

@RestController
@RequestMapping("/firstDemo")
public class DeptController {

	@Resource(name="deptService")
	private DeptServiceImpl deptService;
	
	@RequestMapping("/test")
	public ModelAndView test(){
		Dept d=new Dept();
		d.setDeptno(133333);
		d.setDname("研发部");
		d.setLoc("济南市");
		ModelAndView mv=new ModelAndView();
		mv.addObject("dept",d);
		mv.setViewName("test");
		
		return mv;
	}
	
	@RequestMapping(value="getDeptList",method=RequestMethod.POST)
	public List<Dept> deptList(HttpServletRequest request){
		
		ServletContext application=request.getSession().getServletContext();
		System.out.println(application.getAttribute("test"));
		
		List<Dept> list=deptService.getDeptList();
		
/*		for (Dept dept : list) {
			System.out.println(dept.getDname());
		}
*/		
		return list;
	}
	
}
